<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.yc.comm.Constant"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath(); 
String strUserId = request.getSession().getAttribute("stxtUName").toString();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
  <head>
  	<style type="text/css" media="all">   
	    .allow-float {clear:none!important;} /* 允许该元素浮动 */  
	    .stop-float {clear:both!important;} /* 阻止该元素浮动 */  
	   	.icon-first {float:left;}   
	   	.icon-choosed {float:left;padding:5 0 0 5px;}
	    .icon-second {float:left;padding:0 0 0 20px;} 
	    .win-first {float:left;}   
	    .win-second {float:left;padding:0 0 0 20px;}   
	   	.standby-yes {float:left;}   
	    .standby-no {float:left;padding:0 0 0 20px;}   
	    .age-field {float:left;padding:0 0 0 58px;*padding:0 0 0 50px!important;*padding:0 0 0 50px;}   
	</style> 
  
    <base href="<%=basePath%>"> 
    <link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/ext-all.css">  
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/ext/resources/css/edit-grid.css">  
	<script type="text/javascript" src="<%=path%>/js/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/ext-all.js"></script>
	<script type="text/javascript" src="<%=path%>/js/ext/DWRTreeLoader.js"></script> 
	<script type="text/javascript" src="<%=path%>/js/ext/query-dwr-proxy.js"></script>	
	<script type="text/javascript" src="<%=path%>/js/ext/ext-lang-zh_CN.js"></script>
	<script type='text/javascript' src='/btsm/dwr/interface/JSystemWeb.js'></script>
	<script type='text/javascript' src='/btsm/dwr/engine.js'></script>
	<script type='text/javascript' src='/btsm/dwr/util.js'></script>	 
  </head>
<body> 	 
<div id="mainTabPanelDIV" style="width:100%;height:100%">
	<div id="changeTab"/> 
	<div id="passTab"/>  
</div> 
<script type="text/javascript">

var loginDisabledData = [['<%=Constant.DISABLE_USER%>', '禁止'],['<%=Constant.ENABLE_USER%>', '允许']];
	
var loginDisabledStore = new Ext.data.SimpleStore({
	fields: ['id', 'text'],
	data : loginDisabledData
});

var loginDisabledCombo = new Ext.form.ComboBox({	   
	fieldLabel: '能否登录',
	name: 'logindisabled',	
	width:200,
	valueField :"id",
	displayField: "text",
	mode: 'local',
	selectOnFocus:true,                    
	forceSelection: true,
	blankText:'请选是否允许该用户登录',
	emptyText:'请选是否允许该用户登录',
	hiddenName:'logindisabled',
	triggerAction: 'all',
	allowBlank:false,
	editable:false, 
	store: loginDisabledStore,
	value:0
});

var loginDisabledEditCombo = new Ext.form.ComboBox({	   
	fieldLabel: '能否登录',
	name: 'logindisabled',	
	width:200,
	valueField :"id",
	displayField: "text",
	mode: 'local',
	selectOnFocus:true,                    
	forceSelection: true,
	blankText:'请选是否允许该用户登录',
	emptyText:'请选是否允许该用户登录',
	hiddenName:'logindisabled',
	triggerAction: 'all',
	allowBlank:false,
	editable:false, 
	store: loginDisabledStore,
	value:0
});

 
var roleCombo = new Ext.form.ComboBox({		
		fieldLabel: '用户角色',
		name: 'rights',
		valueField :"id",
		displayField: "text",
		loadingText:'正从后台读取数据..',	
		mode: 'local',
		width:200,
		selectOnFocus:true,                    
		forceSelection: true,
		hiddenName:'rights',
		triggerAction: 'all',
		editable:false, allowBlank:false,
		blankText :'请选择用户角色',
		store: new Ext.data.SimpleStore({
			fields: ["id", "text"],
			data: []
		}) 
	});
	
var roleEditCombo = new Ext.form.ComboBox({		
		fieldLabel: '用户角色',
		name: 'rights',
		valueField :"id",
		displayField: "text",
		loadingText:'正从后台读取数据..',	
		mode: 'local',
		width:200,
		selectOnFocus:true,                    
		forceSelection: true,
		hiddenName:'rights',
		triggerAction: 'all',
		editable:false, allowBlank:false,
		blankText :'请选择用户角色',
		store: new Ext.data.SimpleStore({
			fields: ["id", "text"],
			data: []
		}) 
	});	
	
	
JSystemWeb.getComboArrayForRoles(function(returnData)
{
	var data = []; 
	for (var i = 0; i < returnData.length; i++) { 
		data.push([returnData[i][0], returnData[i][1]]);
	}
	roleCombo.store.loadData(data);
	roleEditCombo.store.loadData(data);
})

var genderData = [['<%=Constant.GENDER_MAN%>', '男'],['<%=Constant.GENDER_FEMAL%>', '女']];
	
var genderStore = new Ext.data.SimpleStore({
	fields: ['id', 'text'],
	data : genderData
});

var genderCombo = new Ext.form.ComboBox({	   
	fieldLabel: '性别',
	name: 'gender',	
	width:200,
	valueField :"id",
	displayField: "text",
	mode: 'local',
	selectOnFocus:true,                    
	forceSelection: true,
	blankText:'请选择性别',
	emptyText:'请选择性别',
	hiddenName:'gender',
	triggerAction: 'all',
	allowBlank:false,
	editable:false, 
	store:genderStore,
	value:'man'
});
  
Ext.onReady(function(){
	Ext.QuickTips.init(); 
	Ext.form.Field.prototype.msgTarget = 'side';

	var mainTabPanelDIV = Ext.get("mainTabPanelDIV");
	var tabPanel = new Ext.TabPanel({
        renderTo:'mainTabPanelDIV',
		resizeTabs:true, // turn on tab resizing
		deferredRender:false,
        minTabWidth:90,
        tabWidth:135,
		enableTabScroll:1,
		height:530,
		margins:'55 0 0 0',	
	    width:mainTabPanelDIV.getComputedWidth(), 
        defaults:{autoHeight:true},
		items:[
	            {contentEl:'changeTab',title: '个人信息',id:1},
	            {contentEl:'passTab',title: '修改密码',id:2}
        ]
    });
	 
	
	
	
	
	
	var btnEditUser = new  Ext.Button({
					text:'修改',
					pressed:true,					 
					handler:{}
				});
	var btnCancelUser = new  Ext.Button({
					text:'取消',
					pressed:true,					 
					handler:{}
				});	
	
	var userForm = new Ext.FormPanel({
			//renderTo:'changeTab',
	    	labelAlign: 'right',
	        frame:true,	        
	        labelWidth:450,	       
			anchor:'90%',
			region:'center',
			height: 260,
			minSize: 200,	
			align:'center',
			buttonAlign:'center', 
			border: false, 
			style: 'margin:0 auto',
			layout:'form', 
			margins:'55 35 100 35',	
	        items: [  
					{
						xtype : 'hidden',
						fieldLabel : "id",
						readOnly : true,
						name : "id"
					},
					{
						xtype:'textfield',
						fieldLabel: '用户ID ',
						name: 'username',
						width:200, 	 
						readOnly: true,
						allowBlank:false,
						blankText :'请输入用户ID'
					},{
						xtype:'textfield',
						fieldLabel: '用户名 ',
						name: 'truename',
						width:200,   
						allowBlank:false,
						blankText :'请输入用户名'
					},genderCombo,					
					{
						xtype:'numberfield',
						fieldLabel: '身份证',
						name: 'identity',
						width:200, 	 
						allowBlank:false,
						blankText :'请输入身份证'
					},					 
					{
						xtype:'datefield',
						format : "Y-m-d",
						fieldLabel: '出生日期',
						width:200,
						name: 'birthday'
					},  
					{
						xtype:'numberfield',
						fieldLabel: '移动电话',
						name: 'mobile',
						width:200 
					},  
					{
						xtype:'numberfield',
						fieldLabel: '家庭电话',
						name: 'telephone',
						width:200,  
						allowBlank:false,
						blankText :'请输入电话号码'
					},
					{
						xtype:'textfield',
						fieldLabel: '家庭地址',
						name: 'address',
						width:200, 	 
						allowBlank:false,
						blankText :'请输入地址信息'
					},  
					{
						xtype:'numberfield',
						fieldLabel: '单位电话',
						name: 'telephoneForCom',
						width:200 
					},
					{
						xtype:'textfield',
						fieldLabel: '单位地址',
						name: 'addresForCom',
						width:200 
					} 
					
									 
				],
			buttons:[
				{
					text : '保存',
					handler :  updateUserInfo
				},{
					text: '取消',
					handler:function()
					{
						isSelected = false ;
						userForm.getForm().reset(); 
					}
				}
			]		
		}); 
 
	var userInfoPanel = new Ext.Panel({
		width    : mainTabPanelDIV.getComputedWidth(),
		height   : 500,
		layout   : 'border',
		renderTo : 'changeTab',
		items    : [
			userForm
		]
	}); 
	
	JSystemWeb.getUserByName("<%=strUserId%>",function(obj) 
		{
			if(obj != null)
			{
				var data = {
							'id':obj.id,
							'username':obj.username,
							'rights':obj.rights,
							'skin':obj.skin,
							'truename':obj.truename,
							'identity':obj.identity,
							'telephone':obj.telephone,
							'address':obj.address,
							'logindisabled':obj.logindisabled,
							'gender':obj.gender,
							'birthday':obj.birthday,
							'email':obj.email,
							'telephoneForCom':obj.telephoneForCom,
							'addresForCom':obj.addresForCom,
							'mobile':obj.mobile
							
						   }; 
				var record = new Ext.data.Record(data);		    	     	    
				userForm.getForm().loadRecord(record);			   
			}
		})
	
	
	function updateUserInfo(){
		var form = userForm.getForm().getValues(false);							
		UserBO = {};
		UserBO.id = form.id;	
		UserBO.gender = form.gender; 		
		UserBO.email = form.email;	
		UserBO.identity = form.identity;	
		UserBO.telephone = form.telephone;	
		UserBO.address = form.address;	
		
		UserBO.telephoneForCom = form.telephoneForCom;	
		UserBO.addresForCom = form.addresForCom;	
		UserBO.mobile = form.mobile;
		UserBO.username = form.username;	
		UserBO.truename = form.truename;		

		var birthdayA = form.birthday; 
		if(birthdayA != "undefined" && birthdayA != "")
		{
			var birthdayDate = new Date();	
			var arrPlanTime = birthdayA.split("-");						
			var yearOth = arrPlanTime[0];
			var monthOth = arrPlanTime[1];
			var dayOth = arrPlanTime[2];
			birthdayDate.setFullYear(yearOth,monthOth-1,dayOth);			
			UserBO.birthday = birthdayDate;
		}else
			UserBO.birthday = new Date();
		
		JSystemWeb.updateUserBySelf(UserBO,function(data)
		{
			if(data)
			{ 
				Ext.Msg.alert('成功',"操作成功！");  
			}else
			{
				Ext.Msg.alert("失败","操作失败!");
			}																
		})						
	}
	
	
	var passForm = new Ext.FormPanel({
		//el:'passTab', 
        frame:true,    
        defaultType: 'textfield',
		labelAlign: 'right',
		frame:true,	        
		labelWidth:450,	       
		anchor:'90%',
		region:'center',
		height: 100,
		minSize: 200,	
		align:'center',
		buttonAlign:'center', 
		border: false, 
		style: 'margin:0 auto',
		layout:'form', 
		margins:'35 35 300 35',	
        items: [
				{
					inputType: 'password', 
					fieldLabel : "原密码",
					allowBlank : false,
					name : "oldPassword",
					width:160,
					blankText :'请输入原密码'	
				},{
					xtype : 'textfield',
					inputType: 'password', 
					fieldLabel : "新密码",
					allowBlank : false,
					name : "passwd",
					width:160,
					blankText :'请输入密码'	
				},{
					xtype : 'textfield',
					inputType: 'password', 
					fieldLabel : "密码确认",
					allowBlank : false,
					name : "passwdTwo",
					width:160,
					blankText :'请输入确认密码'		
				}
        ],
        buttons: [
				{
					text: '保存',
					handler:savePassInfo
				},{
					text: '取消',
					handler:function()
					{
						isSelected = false ;
						passForm.getForm().reset(); 
					}
				}]
    });
	
	var pPanel = new Ext.Panel({
		width    : mainTabPanelDIV.getComputedWidth(),
		height   : 500,
		layout   : 'border',
		renderTo : 'passTab',
		items    : [
			passForm
		]
	}); 
	
	userInfoPanel.render("changeTab");
	tabPanel.activate(1); 
	
	function savePassInfo()
	{
		if (!passForm.getForm().isValid())
			return;	
		var form = passForm.getForm().getValues(false);
		 
		if(form.passwd != form.passwdTwo)
		{
			Ext.Msg.alert("提示","确认密码与第一次密码不一致!");
			return;
		} 
		
		var userId = '<%=strUserId%>'	
		JSystemWeb.isAvialable(userId,form.oldPassword,false,function(data)
		{
			if(data)
			{
				JSystemWeb.updatePassword(userId,form.passwdTwo,function(data)
				{
					if(data)
					{
						Ext.Msg.alert('成功',"操作成功！"); 
					}else
					{
						Ext.Msg.alert("失败","操作失败!");
					}																
				})
			}else
				Ext.Msg.alert("失败","原密码不对，请重新输入!");
		})
	}
	
	
})

</script>
	
</body>
</html>